package pl.mirco.hibernateJPA;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import com.jpa.entities.CtHd;
import com.jpa.entities.HoaDon;
import com.jpa.entities.KhachHang;
import com.jpa.entities.NhanVien;
import com.jpa.entities.SanPham;
import com.jpa.entities.SanPhamHoaDonPK;
import com.jpa.operation.CrudOperation;

/**
 * Hibernate JPA
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hibernate JPA" );
        
        EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("manager1");
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        
        entityManager.getTransaction().begin();
        CrudOperation crudOperation = new CrudOperation();
        
       /* entityManager.persist(crudOperation.createNhanVien());
        entityManager.persist(crudOperation.createKhachHang());
        
       NhanVien nhanVien = entityManager.find(NhanVien.class, "A01");
        KhachHang khachHang = entityManager.find(KhachHang.class, "Ma01");
        
        HoaDon hoaDon = crudOperation.createHoaDon(khachHang, nhanVien);
        entityManager.persist(hoaDon);
        
        SanPham sanPham = crudOperation.createSanPham();
        entityManager.persist(sanPham);*/
        
        SanPham sanPham = entityManager.find(SanPham.class, "SP01");
        HoaDon hoaDon = entityManager.find(HoaDon.class, 1);
        
        CtHd ctHd = crudOperation.createCtHD(hoaDon, sanPham);
        entityManager.persist(ctHd);
        
       
        
        
        
        entityManager.getTransaction().commit();
        entityManager.close();
    }
}
